package com.ruoyi.web.controller.system;

import java.util.LinkedList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.GaeaReportDataSource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GaeaReportDataSet;
import com.ruoyi.system.service.IGaeaReportDataSetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据集管理Controller
 * 
 * @author ruoyi
 * @date 2022-05-01
 */
@Api(value = "数据集管理Controller",tags = "数据源管理Controller")
@RestController
@RequestMapping("/report/resultset")
public class GaeaReportDataSetController extends BaseController
{
    @Autowired
    private IGaeaReportDataSetService gaeaReportDataSetService;

    /**
     * 查询数据集管理列表
     */
    @ApiOperation("查询数据集管理列表")
    @PreAuthorize("@ss.hasPermi('report:resultset:list')")
    @GetMapping("/list")
    public TableDataInfo list(GaeaReportDataSet gaeaReportDataSet)
    {
        GaeaReportDataSet a=new GaeaReportDataSet();
        a.setEnableFlag(1);
        a.setId(2L);
        a.setAccessKey("bf7e108e0631a9353ca59794e3f82bf0");
        a.setCaseResult("[{\"time\":\"2021-08-23\",\"type\":\"成功\",\"nums\":12},{\"time\":\"2021-08-23\",\"type\":\"失败\",\"nums\":1},{\"time\":\"2021-08-24\",\"type\":\"成功\",\"nums\":24},{\"time\":\"2021-08-24\",\"type\":\"失败\",\"nums\":5},{\"time\":\"2021-08-25\",\"type\":\"成功\",\"nums\":13}]");
        a.setCreateBy("admin");
        a.setDynSentence("SELECT time,type,nums from aj_report_comparestack");
        a.setSetCode("compare_ajreport");
        a.setSetName("setName");
        a.setSetType("setType");
        a.setSourceCode("sourceCode");
        a.setUpdateBy("admin");
//        startPage();
        List<GaeaReportDataSet> newlist= new LinkedList<GaeaReportDataSet>();
        newlist.add(a);
//        startPage();

        List<GaeaReportDataSet> list = gaeaReportDataSetService.selectGaeaReportDataSetList(gaeaReportDataSet);
        return getDataTable(newlist);
    }

    /**
     * 导出数据集管理列表
     */
    @ApiOperation("导出数据集管理列表")
    @PreAuthorize("@ss.hasPermi('report:resultset:export')")
    @Log(title = "数据集管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GaeaReportDataSet gaeaReportDataSet)
    {
        List<GaeaReportDataSet> list = gaeaReportDataSetService.selectGaeaReportDataSetList(gaeaReportDataSet);
        ExcelUtil<GaeaReportDataSet> util = new ExcelUtil<GaeaReportDataSet>(GaeaReportDataSet.class);
        util.exportExcel(response, list, "数据集管理数据");
    }

    /**
     * 获取数据集管理详细信息
     */
    @ApiOperation("获取数据集管理详细信息")
    @PreAuthorize("@ss.hasPermi('report:resultset:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(gaeaReportDataSetService.selectGaeaReportDataSetById(id));
    }

    /**
     * 新增数据集管理
     */
    @ApiOperation("新增数据集管理")
    @PreAuthorize("@ss.hasPermi('report:resultset:add')")
    @Log(title = "数据集管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GaeaReportDataSet gaeaReportDataSet)
    {
        return toAjax(gaeaReportDataSetService.insertGaeaReportDataSet(gaeaReportDataSet));
    }

    /**
     * 修改数据集管理
     */
    @ApiOperation("修改数据集管理")
    @PreAuthorize("@ss.hasPermi('report:resultset:edit')")
    @Log(title = "数据集管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GaeaReportDataSet gaeaReportDataSet)
    {
        return toAjax(gaeaReportDataSetService.updateGaeaReportDataSet(gaeaReportDataSet));
    }

    /**
     * 删除数据集管理
     */
    @ApiOperation("删除数据集管理")
    @PreAuthorize("@ss.hasPermi('report:resultset:remove')")
    @Log(title = "数据集管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gaeaReportDataSetService.deleteGaeaReportDataSetByIds(ids));
    }


    /**
     * 数据源状态修改
     */
    @ApiOperation("数据源状态修改")
    @PreAuthorize("@ss.hasPermi('report:resultset:changeStatus')")
    @Log(title = "数据源状态修改", businessType = BusinessType.UPDATE)
    @PostMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody GaeaReportDataSet gaeaReportDataSet)
    {
//        long b = (long)id;
        GaeaReportDataSet newDataSource=gaeaReportDataSetService.selectGaeaReportDataSetById(gaeaReportDataSet.getId());
        newDataSource.setEnableFlag(gaeaReportDataSet.getEnableFlag());
        return toAjax(gaeaReportDataSetService.updateGaeaReportDataSet(newDataSource));
    }

}
